<?PHP
class XMLrequest {
	var $action;
	var $partner_id;//
	var $card_number; //
	var $item_code; //array
	var $date; 		//array
	var $time; 		//array
	var $error;
	
	function XMLrequest($doc) {
	$this->const = new WebServiceConstants();
	
	$ApiKeys = $doc->getElementsByTagName("ApiKey");
	if ($ApiKeys->length!=1) 
		{
		$this->error = "WRONG_APIKEY";
		}
	else { //API is exists
			$api_str = $ApiKeys->item(0)->nodeValue;
			$affill = new AffiliateBO();
			$affill->isxml='1';
			$affill->apikey=$api_str;
			$affill->confirmed = "1";
			$affill->blocked   = "0";
			$affill->Load(0,0);
			if ($affill -> getRowsCount()!=1) 
				{
				$this->error = "WRONG_APIKEY";
				}
			else  // API is right. We get partner Id
			{
			   $affill->Next();
			   $this->partner_id =$affill->id; 
			   $Actions = $doc->getElementsByTagName("Action");
			   if ($Actions->length!=1)
					$this->error = "WRONG_ACTION";
			   else
				$this->action = strtoupper($Actions->item(0)->nodeValue);
				
				$Codes = $doc->getElementsByTagName("ItemCode");
				foreach ($Codes as $Code) $this->item_code[] = $Code->nodeValue;
			   
				$Ids = $doc->getElementsByTagName("CategoryId");
				foreach ($Ids as $Id) $this->cat_id[] = $Id->nodeValue;

				$Dates = $doc->getElementsByTagName("Date");
				foreach ($Dates as $Date) $this->date[] = $Date->nodeValue;

				$Times = $doc->getElementsByTagName("Time");
				foreach ($Times as $Time) $this->time[] = $Time->nodeValue;

				$Ages = $doc->getElementsByTagName("Age");
				foreach ($Ages as $Age) $this->age[] = $Age->nodeValue;

				$Cards = $doc->getElementsByTagName("CardNumber");
				//if (($this->action=="")($Cards->length!=1) 	$this->error = "WRONG_CARD_NUMBER";
				//else 				$this->CardNumber = strtoupper($Cards->item(0)->nodeValue);
			}
		}
	}

}

?>